// Includes
#include "IMesh.h"

namespace EraAstral
{
	namespace graphics
	{
		// IMesh interface constructor
		IMesh::IMesh()
		{
			// Set null pointers
			m_vertices = NULL;
			m_normals = NULL;
			m_texCoords = NULL;
			m_indices = NULL;
			m_texture = NULL;
			
			// Set normal and texture flag to false
			m_hasNormals = false;
			m_hasTexture = false;
		}
		
		// IMesh interface constructor setting vertex, normal, tex coord and index count
		IMesh::IMesh(unsigned int vertexCount, unsigned int normalCount, unsigned int texCoordCount, unsigned int indexCount)
		{
			// Set null pointers
			m_vertices = NULL;
			m_normals = NULL;
			m_texCoords = NULL;
			m_indices = NULL;
			m_texture = NULL;
			
			// Set normal and texture flag to false
			m_hasNormals = false;
			m_hasTexture = false;
			
			// Check normals and textures
			if (normalCount > 0)
				m_hasNormals = true;
			if (texCoordCount > 0)
				m_hasTexture = true;
			
			// Set data
			m_vertexCount = vertexCount;
			m_normalCount = normalCount;
			m_texCoordCount = texCoordCount;
			m_indexCount = indexCount;
		}
		
		// IMesh interface virtual destructor
		IMesh::~IMesh()
		{
			// Delete vertices
			if (m_vertices != NULL)
				delete[] m_vertices;
			
			// Delete normals
			if (m_normals != NULL)
				delete[] m_normals;
				
			// Delete texture coordinates
			if (m_texCoords != NULL)
				delete[] m_texCoords;
				
			// Delete indices
			if (m_indices != NULL)
				delete[] m_indices;
				
			// Delete texture
			if (m_texture != NULL)
				delete m_texture;
		}
		
		// Gets the number of vertices in the mesh
		unsigned int IMesh::GetVertexCount() const
		{
			return m_vertexCount;
		}
		
		// Indicates whether the mesh has normals
		bool IMesh::HasNormals() const
		{
			return m_hasNormals;
		}
		
		// Indicates if the mesh is textured
		bool IMesh::HasTexture() const
		{
			return m_hasTexture;
		}
	}
}
